"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#用例编号:      Security_IAM_PIN_Auth_Func_0202
#用例名称:      首次录入pin码后，锁屏进行解锁
#用例作者:
#修改说明:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.core.test_case import TestCase
from devicetest.aw.OpenHarmony import CommonOH
from aw.Useriam.PinAuth import SecurityUserIamPinAuthApi


class Security_IAM_PIN_Auth_Func_0202(TestCase):

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        self.tests = [
            "test_step1"
        ]
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        print("预置工作：初始化手机开始............" + self.devices[0].device_sn)
        print("预置工作：设置PIN码为123456.........")
        CommonOH.wake(self.device1)
        SecurityUserIamPinAuthApi.setPIN(self.device1, "123456")
        print("预置条件：锁屏")
        CommonOH.goHome(self.device1)
        CommonOH.pressKey(self.device1, "KEYCODE_POWER")

    def test_step1(self):
        print("测试步骤1：进行解锁操作")
        SecurityUserIamPinAuthApi.unlockPIN(self.device1, "123456")
        print("检查点1：检查解锁成功")
        CommonOH.isScreenLocked(self.device1, True)

    def teardown(self):
        print("收尾工作：删除PIN码...................")
        SecurityUserIamPinAuthApi.deletePIN(self.device1, "123456")
        print("收尾工作：PIN码已删除")
        CommonOH.checkIfTextExist(self.device1, "关闭锁屏密码", expect=False)
        print("收尾工作：回到桌面....................")
        CommonOH.goHome(self.device1)
